package com.hanscan.util.language;

import java.io.Serializable;
import java.util.Locale;
import java.util.Properties;
import java.util.ResourceBundle;


/**
 * Clase para cargar un fichero de de un idioma determinado.
 */
public class LanguageConfig extends Properties implements Serializable
{
    //Idiomas
    private String language ;
    private String country ;
    private Locale currentLocale;
    private ResourceBundle message ;

    /**
     * Constructor.
     *
     */
    public LanguageConfig()
    {
//        changeLanguage("", "");
    }


    public void changeLanguage(String lng, String cnt)
    {
       
        language = lng;
        country = cnt;
        currentLocale = new Locale(lng, cnt);
        
        try
        {
            ClassLoader cl= Thread.currentThread().getContextClassLoader();

//            message = ResourceBundle.getBundle("com/hanscan/util/properties/"+"MabasLanguageText",currentLocale,cl);
            if (lng.equals("es"))
            {
                message = ResourceBundle.getBundle("com/hanscan/util/language/"+"spanish");
               
            }
            else
            {
                if (lng.equals("en"))
                {
                    message = ResourceBundle.getBundle("com/hanscan/util/language/"+"english");
                }
            }
            System.out.println("Cambiado idioma : "+lng);
        }
        catch(Exception ex)
        {
            System.out.println(ex.toString());
        }      
    }

    @Override
    public String getProperty(String property_string)
    {       
        String property_result= null;

        property_result = message.getString(property_string);      

        return property_result;
    }

    public String getLanguage()
    {
        return language;
    }

    public void setLanguage(String language)
    {
        this.language = language;
    }


}
